package com.ruoyi.modularbusiness.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.modularbusiness.domain.Formfield;
import com.ruoyi.modularbusiness.service.IFormfieldService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 表单字段Controller
 * 
 * @author 刘振
 * @date 2023-01-05
 */
@RestController
@RequestMapping("/formfield")
public class FormfieldController extends BaseController
{
    @Autowired
    private IFormfieldService formfieldService;

    /**
     * 查询表单字段列表
     */
//    @RequiresPermissions("modularbusiness:formfield:list")
    @GetMapping("/list")
    public TableDataInfo list(Formfield formfield)
    {
        startPage();
        List<Formfield> list = formfieldService.selectFormfieldList(formfield);
        return getDataTable(list);
    }

    /**
     * 导出表单字段列表
     */
    @RequiresPermissions("modularbusiness:formfield:export")
    @Log(title = "表单字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Formfield formfield)
    {
        List<Formfield> list = formfieldService.selectFormfieldList(formfield);
        ExcelUtil<Formfield> util = new ExcelUtil<Formfield>(Formfield.class);
        util.exportExcel(response, list, "表单字段数据");
    }

    /**
     * 获取表单字段详细信息
     */
    @RequiresPermissions("modularbusiness:formfield:query")
    @GetMapping(value = "/{ffid}")
    public AjaxResult getInfo(@PathVariable("ffid") Long ffid)
    {
        return success(formfieldService.selectFormfieldByFfid(ffid));
    }

    /**
     * 新增表单字段
     */
    @RequiresPermissions("modularbusiness:formfield:add")
    @Log(title = "表单字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Formfield formfield)
    {
        return toAjax(formfieldService.insertFormfield(formfield));
    }

    /**
     * 修改表单字段
     */
    @RequiresPermissions("modularbusiness:formfield:edit")
    @Log(title = "表单字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Formfield formfield)
    {
        return toAjax(formfieldService.updateFormfield(formfield));
    }

    /**
     * 删除表单字段
     */
    @RequiresPermissions("modularbusiness:formfield:remove")
    @Log(title = "表单字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ffids}")
    public AjaxResult remove(@PathVariable Long[] ffids)
    {
        return toAjax(formfieldService.deleteFormfieldByFfids(ffids));
    }
}
